package io.renren.modules.efinance.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.efinance.entity.BankcardEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.w3c.dom.stylesheets.LinkStyle;

import java.util.List;

/**
 * 
 * 
 * @author lhf
 * @email i@lhf.com
 * @date 2022-06-24 17:18:43
 */
@Mapper
public interface BankcardDao extends BaseMapper<BankcardEntity> {

    @Update("update bankcard set bankcard_balance=bankcard_balance-#{bankcardBalance} " +
            "where bankcard_idcard='1' and bankcard_balance>=#{bankcardBalance}} ")
    int recharge(BankcardEntity bankcardEntity);

    // # 找出用户222还没有绑定的银行卡
    //select c.bankcard_idcard from bankcard c
    // where c.bankcard_username='222'
    // and not exists(select 1 from bindcard b where b.card_id=c.bankcard_idcard);
    @Select("select c.bankcard_idcard,c.bankcard_bankname from bankcard c where c.bankcard_username=#{username} and not exists(select 1 from bindcard b where b.card_id=c.bankcard_idcard);")
    List<BankcardEntity> queryUnbinds(String username);
    @Select("select c.bankcard_idcard,c.bankcard_bankname from bankcard c where c.bankcard_username=#{username} and  exists(select 1 from bindcard b where b.card_id=c.bankcard_idcard);")
    List<BankcardEntity> queryBinds(String username);
}
